<!DOCTYPE html>
<html>
<div id="tcpCfg" class="portlet-body form">
  <div class="clear">
    <div class="portlet-title" style="margin-bottom: 10px;">
      <div class="caption font-red">
        <i class="icon-settings font-red" style="margin-left: 20px;"></i> <span
          class="caption-subject bold uppercase">基本配置</span>
      </div>
    </div>

    <div class="form-group col-sm-6">
      <label class="control-label col-sm-4 is-required">字符集编码</label>
      <div class="col-sm-8">
        <select name="charset" required field="charset"
                class="form-control select2">
          <option value="UTF-8">UTF-8编码</option>
          <option value="GBK">GBK编码</option>
        </select>
      </div>
    </div>

    <div class="form-group col-sm-6">
      <label class="control-label col-sm-4 is-required">是否启用</label>
      <div class="col-sm-8">
        <select name="enable" required field="enable"
                class="form-control select2">
          <option value="true">是</option>
          <option value="false">否</option>
        </select>
      </div>
    </div>


    <div class="form-group col-sm-6">
      <label class="control-label col-sm-4 is-required">连接类型</label>
      <div class="col-sm-8">
        <select id="tcp_comm_type_Select" name="connetionType" field="connetionType"
                class="form-control select2">
          <option value="short">短连接</option>
          <option value="long">长连接</option>
        </select>
      </div>
    </div>

    <div class="form-group col-sm-6">
      <label class="control-label col-sm-4 is-required">ip地址</label>
      <div class="col-sm-8">
        <input id="ip_txt" name="ip" type="text" field="ip" value="0.0.0.0" class="form-control" required/>
      </div>
    </div>

    <div class="form-group col-sm-6">
      <label class="control-label col-sm-4 is-required">端口号</label>
      <div class="col-sm-8">
        <input id="port_txt" name="port" type="number" field="port" min="1" max="65535" class="form-control"required/>
      </div>
    </div>

    <div id="short_type_div">
      <div class="form-group col-sm-6">
        <label class="control-label col-sm-4" id="conTimeout_title">连接超时时间(秒)</label>
        <div class="col-sm-8">
          <input id="conTimeout_txt" name="conTimeout" field="conTimeout" type="digits" value="20000" class="form-control"/>
        </div>
      </div>
    </div>

    <div id="long_type_div">
      <div class="form-group col-sm-6">
        <label class="control-label col-sm-4">连接超时时间(秒)</label>
        <div class="col-sm-8">
          <input id="conTimeoutLong_txt" name="conTimeout" field="conTimeout" type="digits" value="20000" class="form-control"/>
        </div>
      </div>

      <div class="form-group col-sm-6">
        <label class="control-label col-sm-4">等待连接队列大小</label>
        <div class="col-sm-8">
          <input id="backlog_txt" name="backlog" type="digits" field="backlog" value="50" class="form-control"/>
        </div>
      </div>
    </div>
  </div>


  <div class="clear">
    <div class="portlet-title" id="connectPool_title" style="margin-bottom: 10px;">
      <div class="caption font-red" style="margin-left: 20px;">
        <i class="icon-settings font-red"></i> <span
          class="caption-subject bold uppercase">线程池配置</span>
      </div>
    </div>

    <div id="connectPool_txt">
      <div class="form-group col-sm-6">
        <label class="control-label col-sm-4 is-required">最大线程数</label>
        <div class="col-sm-8">
          <input id="maxSize_txt" name="maxSize" field="maxSize" type="number" min="1" required class="form-control"/>
        </div>
      </div>

      <div class="form-group col-sm-6">
        <label class="control-label col-sm-4 is-required">核心线程数</label>
        <div class="col-sm-8">
          <input id="coreSize_txt" name="coreSize" field="coreSize" type="number" min="1" required class="form-control"/>
        </div>
      </div>
    </div>

    <div class="form-group col-sm-6">
      <label class="control-label col-sm-4 is-required">缓冲队列大小</label>
      <div class="col-sm-8">
        <input id="capacity_txt" name="capacity" field="capacity" type="number" min="1" required class="form-control"/>
      </div>
    </div>
    <div class="form-group col-sm-6">
      <label class="control-label col-sm-4 is-required">空闲线程存活时间(秒)</label>
      <div class="col-sm-8">
        <input id="aliveTime_txt" name="aliveTime" field="aliveTime" type="number" min="1" required class="form-control"/>
      </div>
    </div>
  </div>


  <div class="clear">
    <div class="portlet-title">
      <div class="caption font-red" style="margin-bottom: 20px;">
        <i class="icon-settings font-red" style="margin-left: 20px;"></i> <span
          class="caption-subject bold uppercase">接包规则配置</span>
      </div>
    </div>

    <div class="form-group">
      <label class="control-label col-sm-2">接包规则<span class="required"></span></label>
      <div class="col-sm-9">
        <select id="comm_rule_Select" name="recvRule" field="recvRule" class="form-control select2">
          <option value="">请选择</option>
          <option value="lengthIdentify">字节长度标识</option>
          <option value="lengthByString">字符串长度标识</option>
          <option value="fixLength">定长报文</option>
          <option value="endChar">结束符</option>
        </select>
      </div>
    </div>
    <div id="length_rule_div" style="display: none">
      <div class="form-group col-sm-6">
        <label class="control-label col-sm-4 is-required">报文最大长度</label>
        <div class="col-sm-8">
          <input id="maxFrameLength_txt" name="maxFrameLength" field="maxFrameLength" type="digits" class="form-control" required/>
        </div>
      </div>
      <div class="form-group col-sm-6">
        <label class="control-label col-sm-4 is-required">长度的数据起始位置</label>
        <div class="col-sm-8">
          <input id="lengthFieldOffset_txt" name="lengthFieldOffset" field="lengthFieldOffset" type="digits" class="form-control" required/>
        </div>
      </div>
      <div class="form-group col-sm-6">
        <label class="control-label col-sm-4 is-required">报文数据长度的字段长度</label>
        <div class="col-sm-8">
          <input id="lengthFieldLength_txt" name="lengthFieldLength" field="lengthFieldLength" type="digits" class="form-control"required/>
        </div>
      </div>
      <div class="form-group col-sm-6">
        <label class="control-label col-sm-4 is-required">内容调整长度</label>
        <div class="col-sm-8">
          <input id="lengthAdjustment_txt" name="lengthAdjustment" field="lengthAdjustment" type="number" class="form-control"required/>
        </div>
      </div>

      <div class="form-group col-sm-6">
        <label class="control-label col-sm-4 is-required">跳过字节数</label>
        <div class="col-sm-8">
          <input id="initialBytesToStrip_txt" name="initialBytesToStrip" field="initialBytesToStrip" type="digits" class="form-control" required/>
        </div>
      </div>
    </div>
    <div id="fixLength_div" class="form-group col-sm-6" style="display: none">
      <label class="control-label col-sm-4 is-required">定长报文总长度</label>
      <div class="col-sm-8">
        <input id="len_txt" name="len" field="len" type="digits" class="form-control" required/>
      </div>
    </div>
    <div id="endChar_div" class="form-group col-sm-6" style="display: none">
      <label class="control-label col-sm-4 is-required">结束符</label>
      <div class="col-sm-8">
        <input id="endChar_txt" name="endChar" field="endChar" type="text" class="form-control" required/>
      </div>
    </div>
  </div>

  <div id="heartBeat_div" class="clear">
    <div class="portlet-title" style="margin-bottom: 10px;">
      <div class="caption font-red">
        <i class="icon-settings font-red" style="margin-left: 20px;"></i> <span
          class="caption-subject bold uppercase">心路规则配置</span>
      </div>
    </div>
    <div class="form-group col-sm-6">
      <label class="control-label col-sm-4">心跳时间间隔(秒)</label>
      <div class="col-sm-8">
        <input id="interval_txt" name="interval" field="interval" value="30" type="digits" class="form-control"/>
      </div>
    </div>
    <div class="form-group col-sm-6">
      <label class="control-label col-sm-4">心跳包内容串</label>
      <div class="col-sm-8">
        <input id="content_txt" name="content" field="content" type="digits" class="form-control"/>
      </div>
    </div>
  </div>

  <div id="out_extcall_div" class="clear">
    <div class="portlet-title" style="margin-bottom: 10px;">
      <div class="caption font-red">
        <i class="icon-settings font-red" style="margin-left: 20px;"></i> <span
          class="caption-subject bold uppercase">配置三方插件</span>
      </div>
    </div>
    <div class="form-group col-sm-6">
      <label class="control-label col-sm-4">插件类</label>
      <div class="col-sm-8">
        <input id="exterClass_txt" name="exterClass" field="exterClass" type="text" class="form-control"/>
      </div>
    </div>
    <div class="form-group col-sm-6">
      <label class="control-label col-sm-4">报文与通讯函数</label>
      <div class="col-sm-8">
        <input id="externPackAndSend_txt" name="externPackAndSend" field="externPackAndSend" type="text" class="form-control"/>
      </div>
    </div>
    <div class="form-group col-sm-6">
      <label class="control-label col-sm-4 is-required">组包函数</label>
      <div class="col-sm-8">
        <input id="externPack_txt" name="externPack" field="externPack" type="text" class="form-control"/>
      </div>
    </div>
    <div class="form-group col-sm-6">
      <label class="control-label col-sm-4">解包函数</label>
      <div class="col-sm-8">
        <input id="externUnpack_txt" name="externUnpack" field="externUnpack" type="text" class="form-control"/>
      </div>
    </div>
    <div class="form-group col-sm-6">
      <label class="control-label col-sm-4">通讯函数<span class="required"></span></label>
      <div class="col-sm-8">
        <input id="externSend_txt" name="externSend" field="externSend" type="text" class="form-control"/>
      </div>
    </div>
    <div class="form-group col-sm-6">
      <label class="control-label col-sm-4">组包前处理</label>
      <div class="col-sm-8">
        <input id="beforePack_txt" name="beforePack" field="beforePack" type="text" class="form-control"/>
      </div>
    </div>
    <div class="form-group col-sm-6">
      <label class="control-label col-sm-4">发送前请求处理</label>
      <div class="col-sm-8">
        <input id="beforeSend_txt" name="beforeSend" field="beforeSend" type="text" class="form-control"/>
      </div>
    </div>
    <div class="form-group col-sm-6">
      <label class="control-label col-sm-4">解包前处理</label>
      <div class="col-sm-8">
        <input id="beforeUnpack_txt" name="beforeUnpack" field="beforeUnpack" type="text" class="form-control"/>
      </div>
    </div>
    <div class="form-group col-sm-6">
      <label class="control-label col-sm-4">解包后处理</label>
      <div class="col-sm-8">
        <input id="beforeReturn_txt" name="beforeReturn" field="beforeReturn" type="text" class="form-control"/>
      </div>
    </div>
  </div>
</div>
<script>
  $(function () {
    // debugger
    bindSelectEvents();
    initDom();
    // var flag = com_action_flag;
    var flag = 'add';
    if (flag == "add") {
      var temp_ip = '[[${ip}]]';
      if (temp_ip != "" && null != temp_ip) {
        // swal({
        //   title: "你加载的配置已经存在，确认需要修改吗？",
        //   text: "",
        //   type: "warning",
        //   showCancelButton: true,
        //   cancelButtonText: "取消",
        //   closeOnConfirm: true,
        //   confirmButtonText: "确定"
        // }, function (isConfirm) {
        //   if (!isConfirm) {
        //     $("#packet_context_div").empty();
        //     $("#comm_cfg_form").hide();
        //   }
        // });
        // $.modal.confirm('你加载的配置已经存在，确认需要修改吗？')
      }
    }

  });

  function initDom() {
    // var type = [[${type}]];
    // if("IN"==type){
    // 	$("#id_div").hide();
    // 	$("#out_extcall_div").remove();
    // }else if ("OUT"==type){
    // 	$("#id_div").val("");
    // 	$("#id_div").show();
    // 	$("#out_extcall_div").show();
    // }
    if ($("#commType").val() == "IN") {
      $("#out_extcall_div").remove();
      $("#conTimeout_title").remove();
      $("#conTimeout_txt").parent().remove();
    } else if ($("#commType").val() == "OUT") {
      $("#out_extcall_div").show();
      //接出通讯不显示连接池
      $("#connectPool_title").remove();
      $("#connectPool_txt").remove();
    }
    var rule = recvRule
    dealRuleSelect(rule);
    // var commType = $("#tcp_comm_type_Select").val();
    var commType = connetionType
    dealCommType(commType);
  }

  function dealRuleSelect(value) {
    if (value == "lengthIdentify" || value == "lengthByString") {
      enableAll("length_rule_div");
      $("#length_rule_div").show();
      disabledAll("fixLength_div");
      disabledAll("endChar_div");
      $("#fixLength_div").hide();
      $("#endChar_div").hide();
    } else if (value == "fixLength") {
      enableAll("fixLength_div");
      $("#fixLength_div").show();

      disabledAll("length_rule_div");
      disabledAll("endChar_div");
      $("#length_rule_div").hide();
      $("#endChar_div").hide();
    } else if (value == "endChar") {
      enableAll("endChar_div");
      $("#endChar_div").show();
      disabledAll("length_rule_div");
      disabledAll("fixLength_div");
      $("#length_rule_div").hide();
      $("#fixLength_div").hide();
    } else if (value == "" || null == value) {
      $("#length_rule_div").hide();
      $("#fixLength_div").hide();
      $("#endChar_div").hide();
      disabledAll("length_rule_div");
      disabledAll("fixLength_div");
      disabledAll("endChar_div");
    }
  }


  function dealCommType(value) {
    enableAll("long_type_div");
    enableAll("heartBeat_div");
    enableAll("short_type_div");
    if (value == "long") {
      $("#long_type_div").show();
      $("#heartBeat_div").show();
      $("#short_type_div").hide();
      disabledAll("short_type_div");
    } else if (value == "short") {
      $("#long_type_div").hide();
      $("#heartBeat_div").hide();
      disabledAll("long_type_div");
      disabledAll("heartBeat_div");
      $("#short_type_div").show();
    } else {  //如果没有选择，直接用默认短连接显示
      $("#long_type_div").hide();
      $("#heartBeat_div").hide();
      disabledAll("long_type_div");
      disabledAll("heartBeat_div");
      $("#short_type_div").show();
    }
  }

  //绑定接包规则的选择事件
  function bindSelectEvents() {
    $("#comm_rule_Select").bind("change", function () {
      var value = $(this).val();
      dealRuleSelect(value)
    });

    $("#tcp_comm_type_Select").bind("change", function () {
      var value = $(this).val();
      dealCommType(value);
    });
  }


</script>